<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<!--{hook admin_sort_list_start.htm}-->
<link rel="stylesheet" type="text/css" href="./view/vendor/datatables/css/dataTables.bootstrap4.css">
<link rel="stylesheet" href="./view/vendor/bootstrap-select/css/bootstrap-select.css">
<div class="row">
	<div class="col-12">
		<div class="btn-group mb-3" role="group">
			<?php echo admin_tab_active($menu['forum']['tab'], 'sort');?>
		</div>
		<div class="card">
			<div class="card-body">
				<form action="<?php echo url('forum-sort');?>" method="post" id="form">
					<div class="table-responsive arrlist">
						<table class="table table-striped table-bordered first" style="min-width: 800px">
							<thead>
								<tr align="center">
									<th>分类id</th>
									<th>板块名称</th>
									<th>分类名称</th>
									<th>分类排序</th>
									<!-- <th width="100" class="text-center"><?php echo lang('forum_edit');?></th> -->
									<th><?php echo lang('forum_delete');?></th>
								</tr>
							<thead>
							<tbody>
								<?php foreach($sortlist as $_sid=>$_sort) { ?>
								<tr align="center" rowid="<?php echo $_sid; ?>">
									<td class="50"><input type="text" class="form-control" name="sid[<?php echo $_sid;?>]" value="<?php echo $_sort['sid']; ?>"  placeholder="<?php echo lang('sort_id');?>" /></td>
									<!-- <td><p class=""><?php echo $_sort['f_name'];?></p></td> -->
									<td>
										<select name="fid[<?php echo $_sid;?>]" class="form-control selectpicker>
											<?php foreach($forumlist as $forum){ ?>
  												<option 
  													value="<?php echo $forum['fid']; ?>"
  													<?php if($_sort['fid'] == $forum['fid']){ ?>
  													selected="selected"
													  <?php } ?>
													
  													>
  													<?php echo $forum['name']; ?>
  												</option>
  											<?php } ?>
										</select>
									</td>
									<td><input type="text" class="form-control" name="name[<?php echo $_sid;?>]" value="<?php echo $_sort['name']; ?>" placeholder="分类名称" /></td>
									<td><input type="text" class="form-control" name="orderby[<?php echo $_sid;?>]" value="<?php echo $_sort['orderby']; ?>" placeholder="排序" /></td>
									<!-- <td><a class="btn row_edit" role="button" tabindex="0">编辑</a></td> -->
									<td><a class="btn row_delete" role="button" tabindex="0">删除</a></td>
								</tr>
								<?php } ?>
							</tbody>
						</table>
					</div>
					<p><a role="button" class="btn row_add">[+]<?php echo lang('add_new_line');?></a></p>
					<p class="text-center">
						<button type="submit" class="btn btn-primary" id="submit" data-loading-text="<?php echo lang('submiting');?>..." style="width: 10rem;"><?php echo lang('confirm');?></button>
					</p>
				</form>
				<p class="small text-grey"><?php echo lang('tips');?>：<?php echo lang('sort_edit_tip');?></p>
			</div>
		</div>
	</div>
</div>


<!--{hook admin_sort_list_end.htm}-->



<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>
<script src="./view/vendor/bootstrap-select/js/bootstrap-select.js"></script>
<script>


//if(!debug) $.alert('<?php echo lang('sort_edit_tip');?>');

//var maxsid = <?php //echo $maxsid;?>;
var maxsid = <?php echo $maxsid; ?> ;
var jform = $("#form");
var jsubmit = $("#submit");

jform.base64_encode_file(); // 对文件进行 base64 编码，处理文件上传，很方便

jform.on('submit', function(){
	jform.reset();
	var postdata = jform.serialize();
	jsubmit.button('loading');
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.text(message).delay(3000).location();
			return;
		} else {
			alert(message);
			jsubmit.button('reset');
		}
	});
	return false;
});

// 编辑
var jarrlist = $('.arrlist');
var jedit = $('a.row_edit');
jarrlist.on('click', 'a.row_edit', function() {
	var jthis = $(this);
	var jtr = jthis.parents('tr');
	var rowid = jtr.attr('rowid');
	window.location = xn.url('sort-update-'+rowid);
});

// 删除
var jdelete = $('a.row_delete');
jarrlist.on('click', 'a.row_delete', function() {
	var jthis = $(this);
	var jtr = jthis.parents('tr');
	var rowid = jtr.attr('rowid');
	if(rowid == 1) {
		$.alert('<?php echo lang('sort_cant_delete_system_reserved');?>');
		return;
	}
	jtr.remove();
	return false;
});
// 增加
var jadd = $('a.row_add');
jadd.on('click', function() {
	var jclone = jarrlist.find('tr').last().clone();
	jclone.insertAfter(jarrlist.find('tr').last());
	var jsid = jclone.find('input[name^="sid"]');
	//var rowid = xn.intval(jsid.val()) + 1;
	var rowid = ++maxsid;
	jsid.val(rowid);
	jclone.attr('rowid', rowid);
	
	// 清空值
	jclone.find('input').not('[name^="sid"]').val('');
	
	// 修改 [] 中的值为 rowid
	jclone.find('input').attr_name_index(rowid);
	jclone.find('select').attr_name_index(rowid);
	
	return false;
});


$('#nav li.nav-item-sort').addClass('active');

</script>

<!--{hook admin_sort_list_js.htm}-->